package proyecto.login;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends ActionForm {
	private String usuario;
	private String password;
	
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getUsuario() {
		return usuario;
	}
	
	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}
	
	
	public void reset(ActionMapping mapping,
					HttpServletRequest request) {
		this.password = null;
		this.usuario = null;
	}
	
	
	public ActionErrors validate(ActionMapping mapping,
								HttpServletRequest request) 
	{		
		ActionErrors errors = new ActionErrors();
		
		if ( (usuario == null ) || (usuario.length() == 0) ) {
			errors.add("usuario",
			new ActionError("Login.error.usuario.requerido"));
		}
		
		if ( (password == null ) || (password.length() == 0) ) {
			errors.add("password",
			new ActionError("Login.error.password.requerido"));
		}
				
		return errors;
	}
}
